<template>
  <div style="position:relative">
    <!-- :params="fetchParams" -->
    <FilterTable
      ref="table"
      :columns="columns"
      :dataSource="list"
      :isColumnFilter="false"
      :isToperInfo="false"
      :isSelectColumn="false"
      :onSyncTableData="syncTableFun"
      :onColumnsChange="columns => (this.columns = columns)"
    >
      <!-- <template slot="controls" slot-scope="props">
           <el-button
             size="small"
             type="primary"
             icon="el-icon-plus"
             @click="addFjxmHandle()"
           >新增</el-button>
         </template> -->
    </FilterTable>
    <!-- <BaseDialog
      :visible.sync="visibleFjxm"
      title="附加项目选择"
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto'}"
      destroyOnClose>
      <AddFjxm  ref="addFjxm"  @closeFj="closeAddfjxm"/>
    </BaseDialog> -->
  </div>
</template>
<script>
//  import AddFjxm from '../addXM/addfjxm'
import { dictionary } from '@/utils/dictMixin';
import { detailsFjxm, getPartitionList } from '@/api/repair/repair/activitesManage';
// import { getFwhdFjxmList , getFwhdSfList} from '@/api/repair/repairReception/customer/activity.js';

let _this;

export default {
  name: 'Fjxm',
  components: {
    // AddFjxm
  },
  mixins: [dictionary],
  props: ['detaildata'],
  data() {
    // this.BaseTable = null;
    return {
      visibleFjxm: false,
      columns: this.createTable(),
      fetchApi: '',
      // fetchParams: {xhrAbort: false},
      list: [],
      tableData: []
    };
  },
  created() {
    _this = this;
    _this.getPartitionList();
    _this.detailsFjxm();
  },
  methods: {
    // 收费区分下拉框
    async getPartitionList() {
      const res = await getPartitionList();
      this.columns[3].editItems = res.data.map(x => ({ value: x.CHARGE_PARTITION_CODE, text: x.CHARGE_PARTITION_NAME }));
    },
    // 获取回显数据方法
    async detailsFjxm() {
      let res = await detailsFjxm(this.detaildata);
      // ADD_ITEM_AMOUNT附加项目费
      // DISCOUNT折扣率
      // RECEIVE_AMOUNT折扣后附加项目费
      res.data.rows.forEach(x => {
        if (isNaN(Number(x.DISCOUNT)) || isNaN(Number(x.ADD_ITEM_AMOUNT))) {
          x.RECEIVE_AMOUNT = 0;
        } else {
          x.RECEIVE_AMOUNT = Number(x.DISCOUNT) * Number(x.ADD_ITEM_AMOUNT);
        }
        if(x.CHARGE_PARTITION_CODE == 'S'||x.CHARGE_PARTITION_CODE == 'N'){
          x.RECEIVE_AMOUNT = 0;
        }
      });
      _this.$refs.table.$refs.pageTable.EXECUTE_INSERT(res.data.rows);
    },
    // closeAddfjxm (val) {
    //   this.visibleFjxm = false
    //   if (val != false){
    //     this.$refs.table.$refs.pageTable.EXECUTE_INSERT(val)
    //     // this.list.push(val)
    //     // this.$refs.table.$refs.pageTable.EXECUTE_INSERT(val)
    //   }
    // },
    ceshi(val) {
      _this.$emit('changethree', _this.list);
    },
    // addFjxmHandle() {
    //   this.visibleFjxm = true
    // },
    // 传给父组件的数据
    syncTableFun(val) {
      this.tableData = val;
    },
    // 维修材料表单数据删除
    delete(val) {
      let a = [];
      a.push(val);
      this.$refs.table.$refs.pageTable.EXECUTE_DELETE(a);
    },
    createTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        // {
        //     title: '操作',
        //     dataIndex: 'column-action',
        // },
        {
          title: '附加项目代码',
          dataIndex: 'ADD_ITEM_CODE',
          sorter: true
        },
        {
          title: '附加项目名称',
          dataIndex: 'ADD_ITEM_NAME',
          sorter: true
        },
        {
          title: '收费区分',
          dataIndex: 'CHARGE_PARTITION_CODE',
          sorter: true,
          filterItems: [],
          editable: true,
          editType: 'select',
          editItems: [],
          disabled: true
          // render: props => {
          //   return <span>{this.func(props.row.CHARGE_PARTITION_CODE,4)}</span>;
          //   }
        },
        {
          title: '附加项目费',
          dataIndex: 'ADD_ITEM_AMOUNT',
          precision: 2,
          sorter: true
        },
        {
          title: '折扣率',
          dataIndex: 'DISCOUNT',
          sorter: true
        },
        {
          title: '折扣后附加项目费',
          dataIndex: 'RECEIVE_AMOUNT',
          precision: 2,
          sorter: true
        },
        {
          title: '附加项目ID',
          dataIndex: 'ITEM_ID',
          sorter: true
        }
      ];
    },
    async getFwhdFjxmList(row) {
      const res = await getFwhdFjxmList(row, {
        creditTimes: 1.0,
        afterlabour: 0,
        zkAmountLabour: 0,
        afterDiscountAmountPart: 0,
        zkAmountPart: 0,
        fag: 'U',
        labourList: '',
        partList: '',
        subjoinList: '',
        modelList: '',
        vehicleList: '',
        order: 'asc',
        limit: 10,
        offset: 0,
        dmsFuncId: 35100010,
        _: 1565681747515
      });
      this.list = res.rows;
    },
    async getFwhdSfList() {
      const res = await getFwhdSfList();
      this.columns[4].filterItems = res.map(x => ({ value: x.CHARGE_PARTITION_CODE, text: x.CHARGE_PARTITION_NAME }));
    },
    func(val, num) {
      if (val) {
        const res = this.columns[num].filterItems.find(x => x.value == val);
        return res.text;
      }
    }
  }
};
</script>
